package com.briup.smartcity.web.controller;

import com.github.pagehelper.PageInfo;
import com.briup.smartcity.bean.BaseConfig;
import com.briup.smartcity.service.IBaseConfigService;
import com.briup.smartcity.utils.Result;
import com.briup.smartcity.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 基础配置类
 */
@Api(tags = "系统配置模块")
@RequestMapping("/auth/config")
@RestController
public class BaseConfigController {

    @Autowired
    private IBaseConfigService iBaseConfigService;

    @ApiOperation(value = "查询当前启用的系统配置")
    @GetMapping("/current/config/yes")
    public Result findConfig(){

        BaseConfig baseConfig = iBaseConfigService.currentConfigYes();

        return ResultUtil.success(baseConfig);
    }

    @ApiOperation(value = "通过id删除配置信息")
    @DeleteMapping("/deleteById")
    public Result deleteConfigId(Integer id){
        iBaseConfigService.deleteById(id);
        return ResultUtil.success();
    }
    @ApiOperation(value = "保存配置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "configId",value = "配置id"),
            @ApiImplicitParam(name = "configName",value = "配置系统名字"),
            @ApiImplicitParam(name = "configInfo",value = "配置信息"),
            @ApiImplicitParam(name = "configIcon",value = "配置图片"),
            @ApiImplicitParam(name = "configStatus",value = "配置状态")
    })
    @PostMapping("/save")
    public Result savaConfig(BaseConfig baseConfig){

        iBaseConfigService.saveConfig(baseConfig);
        return ResultUtil.success();
    }

    @ApiOperation(value = "更新配置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "configId",value = "配置id"),
            @ApiImplicitParam(name = "configName",value = "配置系统名字"),
            @ApiImplicitParam(name = "configInfo",value = "配置信息"),
            @ApiImplicitParam(name = "configIcon",value = "配置图片"),
            @ApiImplicitParam(name = "configStatus",value = "配置状态")
    })
    @PutMapping("/update")
    public Result updateConfig(BaseConfig baseConfig){
        iBaseConfigService.updateConfig(baseConfig);
        return ResultUtil.success();
    }
    @ApiOperation(value = "更新配置状态")
    @PutMapping("/update/status")
    public Result updateConfigStatus(Integer id,Integer status){
        iBaseConfigService.changeConfigStatus(id,status);
        return ResultUtil.success();
    }

    @ApiOperation("分页查询配置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小")
    })
    @GetMapping("/page/query")
    public Result pageAllConfig(Integer pageNum,Integer pageSize){

        PageInfo<BaseConfig> pageInfo = iBaseConfigService.findAllWithPage(pageNum,pageSize);

        return ResultUtil.success(pageInfo);
    }

}
